﻿using System;

namespace StartReading.Security.Validation
{
    class EmptyStringValidation : IValidation<String, String>
    {
        private EmptyStringValidation()
        {
        }

        #region Lazy Singleton Thread-Safe
        private static class EmptyStringValidationHolder
        {
            static EmptyStringValidationHolder()
            {
            }

            internal static readonly EmptyStringValidation EmptyStringValidation = new EmptyStringValidation();
        }

        /// <summary>
        /// Gets an EmptyStringValidation instance
        /// </summary>
        public static EmptyStringValidation Instance
        {
            get { return EmptyStringValidationHolder.EmptyStringValidation; }
        }
        #endregion

        /// <summary>
        /// Validates Null or Empty string.
        /// Throws ArgumentException if string is either Null or Empty.
        /// </summary>
        /// <param name="item">String to be validated</param>
        /// <param name="itemName">Name of validated string for ArgumentException message</param>
        /// <exception cref="System.ArgumentException"></exception>
        public void IsValid( string item, string itemName )
        {
            if ( String.IsNullOrEmpty( item ) )
                throw new ArgumentException( String.Format( "{0} cannot be empty.", itemName ) );
        }
    }
}
